#ifndef BMP085_h
#define BMP085_h

#include "Arduino.h"
#include "WString.h"

/*
BMP085 implements an altimeter/barometer interface to the BOSCH BMP085 pressure sensor.

.begin() methods read and store the sensor calibration constants.  Calling with an 
altitude will set the current site altitude (AMSL).  A ground level can be set to
obtain altitude readings AGL.

Pressure readings are in Pa, altitudes are in cm, Temp in 0.1 C
*/

class BMP085
{
  public:
    BMP085(void);
    void begin(void);
    void begin(long site_alt);

    long T_alt;            // Altimeter Temperature reading, in 0.1 C
    long p;                // pressure in Pa, read at last pressure()
    long alt_0;            // altitude offset, cm
    long agl_0;            // ground level, cm, AMSL
    
    long pressure(void);   // Read pressure (in Pa) from last start_pressure()
    long altitude(void);   // Absolute altitude above sea level, cm
    long agl(void);        // Altitude above agl_0, cm

    void start_temp(void); // Starts temperature reading
    void get_temp(void);   // Gets temperature reading from last start_temp()
    void start_pressure(void);    // Starts pressure reading
    void set_alt(long site_alt);  // Current altitude setting

    int ALT_OVRS;          // BMP085 oversampling_setting
    int ALT_SHFT;          // BMP Oversampling multiplier shift (=8 - ALT_OVRS)

    String ACconst(void);  // Returns the internal "A" Constants, as a String (for debug)
    String BMconst(void);  // Returns the internal "B" Constants, as a String (for debug)

      
  private:
    void _init(void); // Initializes BMP085
    int _pADDR;    // I2C Bus Address of BMP085 Pressure Sensor
    byte _pCTRL;    // BMP085 Control Register Address
    byte _pTEMP;    // BMP085 Start Temp Measurement
    byte _pDATA;    // BMP085 First Calibration Data Register Address
    byte _pATOD;    // BMP085 A/D Register Address
    byte _pMODE;    // BMP085 Start Press Measurement
    int AC1;
    int AC2;
    int AC3;
    unsigned int AC4;
    unsigned int AC5;
    unsigned int AC6;
    int xB1;
    int B2;
    int MB;
    int MC;
    int MD;
    long B5;        // Intermediate pressure cal value


};

#endif
